<?php include('../includes/db_connect.php'); 
include('../includes/phpheader.php');
$id = $_POST["id"];

$isGuardian = $_POST["isGuardian"];
$gName = $_POST["guardianName"];
$gRelationship = $_POST["guardianRelationship"];
$gHomePhone = $_POST["guardianHomePhone"];
$gWorkPhone = $_POST["guardianWorkPhone"];
$gAddress = $_POST["guardianAddress"];
$gCity = $_POST["guardianCity"];
$gStateId = $_POST["guardianState"];
$gZip = $_POST["guardianZip"];

$appSig = $_POST["applicantSig"];
$appSigDateMonth = $_POST["applicantSigDateMonth"];
$appSigDateDay = $_POST["applicantSigDateDay"];
$appSigDateYear = $_POST["applicantSigDateYear"];
$appDate = $appSigDateYear."-".$appSigDateMonth."-".$appSigDateDay;

$gSig = $_POST["guardianSig"];
$gSigDateMonth = $_POST["guardianSigDateMonth"];
$gSigDateDay = $_POST["guardianSigDateDay"];
$gSigDateYear = $_POST["guardianSigDateYear"];
$gDate = $gSigDateYear."-".$gSigDateMonth."-".$gSigDateDay;

$sSig = $_POST["staffSig"];
$sSigDateMonth = $_POST["staffSigDateMonth"];
$sSigDateDay = $_POST["staffSigDateDay"];
$sSigDateYear = $_POST["staffSigDateYear"];
$sDate = $sSigDateYear."-".$sSigDateMonth."-".$sSigDateDay;

$appGrievanceSig = $_POST["applicantGrievanceSig"];
$appGrievanceSigDateMonth = $_POST["applicantGrievanceSigDateMonth"];
$appGrievanceSigDateDay = $_POST["applicantGrievanceSigDateDay"];
$appGrievanceSigDateYear = $_POST["applicantGrievanceSigDateYear"];
$appGrievanceDate = $appGrievanceSigDateYear."-".$appGrievanceSigDateMonth."-".$appGrievanceSigDateDay;

$gGrievanceSig = $_POST["guardianGrievanceSig"];
$gGrievanceSigDateMonth = $_POST["guardianGrievanceSigDateMonth"];
$gGrievanceSigDateDay = $_POST["guardianGrievanceSigDateDay"];
$gGrievanceSigDateYear = $_POST["guardianGrievanceSigDateYear"];
$gGrievanceDate = $gGrievanceSigDateYear."-".$gGrievanceSigDateMonth."-".$gGrievanceSigDateDay;

$sGrievanceSig = $_POST["staffGrievanceSig"];
$sGrievanceSigDateMonth = $_POST["staffGrievanceSigDateMonth"];
$sGrievanceSigDateDay = $_POST["staffGrievanceSigDateDay"];
$sGrievanceSigDateYear = $_POST["staffGrievanceSigDateYear"];
$sGrievanceDate = $sGrievanceSigDateYear."-".$sGrievanceSigDateMonth."-".$sGrievanceSigDateDay;


$query = "select id from intake2 where consumer_id = ".$id;

if(mysql_fetch_array(mysql_query($query))) {
	$query = "update intake2 set is_guardian = ".$isGuardian.", guardian_name = '".$gName.
	"', guardian_relationship = '".$gRelationship."', guardian_address ='".$gAddress."', guardian_city = '".
	$gCity."', guardian_state_id = ".$gStateId.", guardian_zip = '".$gZip."', guardian_home_phone = '".
	$gHomePhone."', guardian_work_phone='".$gWorkPhone."', applicant_signature = '".$appSig.
	"', applicant_signature_date= '".$appDate."', guardian_signature = '".$gSig.
	"', guardian_signature_date= '".$gDate."', staff_signature = '".$sSig."', staff_signature_date = '".
	$sDate."', applicant_grievance_signature = '".$appGrievanceSig."', applicant_grievance_signature_date= '".
	$appGrievanceDate."', guardian_grievance_signature = '".$gGrievanceSig."', guardian_grievance_signature_date= '".
	$gGrievanceDate."', staff_grievance_signature = '".$sGrievanceSig."', staff_grievance_signature_date = '".
	$sGrievanceDate."' where consumer_id = ".$id;
} else {
	$query = "insert into intake2 (consumer_id, is_guardian, guardian_name, guardian_relationship, guardian_address,
	guardian_city, guardian_state_id, guardian_zip, guardian_home_phone, guardian_work_phone, applicant_signature, 
	applicant_signature_date, guardian_signature, guardian_signature_date, staff_signature, staff_signature_date, 
	applicant_grievance_signature, applicant_grievance_signature_date, guardian_grievance_signature, 
	guardian_grievance_signature_date, staff_grievance_signature, staff_grievance_signature_date) 
	VALUES 
		(".$id.", ".$isGuardian.", '".$gName."', '".$gRelationship."', '".$gAddress."', '".$gCity."', ".
		$gStateId.", '".$gZip."', '".$gHomePhone."', '".$gWorkPhone."', '".$appSig."', '".$appSigDate."', '".
		$gSig."', '".$gDate."', '".$sDate."', '".$sDate."', '".$appGrievanceSig."', '".$appGrievanceSigDate."', '".
		$gGrievanceSig."', '".$gGrievanceDate."', '".$sGrievanceDate."', '".$sGrievanceDate."');";
}

if(mysql_query($query)) {
  header("Location:../admin.php?action=cieedit&id=".$id."&Status=Intake 2 Form Submitted Successfully");
  exit();
	//echo "Success <br/>".$query;
} else {
	header("Location:../admin.php?action=cieedit&id=".$id."&Error=Unable to process Intake 2 Form due to system error.  Please contact system administrator.");
  exit();
	//echo "Failure <br/>".$query;
}


